<div class="panel panel-default" ng-controller="tcpdump_Controller"><div class="panel-heading"><h4 class="panel-title pull-left">{{title}}</h4><span class="pull-right">{{version}}</span><div class="clearfix"></div></div></div>

<div class="row">
    <div class="col-md-4">
        <div class="panel panel-default" ng-controller="tcpdump_ControlsController">
            <div class="panel-heading">
				<h3 class="panel-title">Controls</h3>
            </div>
			<div class="panel-body">
				<table style="width:100%">
					<tr>
						<td style="padding-bottom: .5em;" class="text-muted">Dependencies</td>
            <td ng-hide="$root.status.installed" style="text-align:right;padding-bottom: .5em;"><button type="button" style="width: 90px;" class="btn btn-{{installLabel}} btn-xs" data-toggle="modal" data-target="#dependenciesInstallModal" ng-disabled="processing">{{install}}</button></td>
            <td ng-show="$root.status.installed" style="text-align:right;padding-bottom: .5em;"><button type="button" style="width: 90px;" class="btn btn-{{installLabel}} btn-xs" data-toggle="modal" data-target="#dependenciesRemoveModal" ng-disabled="processing">{{install}}</button></td>
					</tr>
					<tr ng-show="$root.status.installed">
						<td style="padding-bottom: .5em;" class="text-muted">tcpdump</td>
						<td style="text-align:right;padding-bottom: .5em;"><button type="button" style="width: 90px;" class="btn btn-{{statusLabel}} btn-xs" ng-disabled="starting" ng-click="toggletcpdump()">{{status}}</button></td>
					</tr>
				</table>
			</div>

      <div class="modal fade" id="dependenciesInstallModal" tabindex="-1" role="dialog" aria-labelledby="dependenciesModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="dependenciesInstallModalLabel">Install dependencies</h4>
            </div>
            <div class="modal-body">
              All required dependencies have to be installed first. This may take a few minutes.<br /><br />
              Please wait, do not leave or refresh this page. Once the install is complete, this page will refresh automatically.
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-info" ng-click="handleDependencies('internal')" data-dismiss="modal">Internal</button>
              <button type="button" class="btn btn-info" ng-hide="device == 'tetra' || sdAvailable == false" ng-click="handleDependencies('sd')" data-dismiss="modal">SD Card</button>
            </div>
          </div>
        </div>
      </div>

      <div class="modal fade" id="dependenciesRemoveModal" tabindex="-1" role="dialog" aria-labelledby="dependenciesModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="dependenciesRemoveModalLabel">Remove dependencies</h4>
            </div>
            <div class="modal-body">
              All required dependencies will be removed. This may take a few minutes.<br /><br />
              Please wait, do not leave or refresh this page. Once the remove is complete, this page will refresh automatically.
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
              <button type="button" class="btn btn-info" ng-click="handleDependencies()" data-dismiss="modal">Confirm</button>
            </div>
          </div>
        </div>
      </div>

        </div>
    </div>
</div>

<div class="panel panel-default" ng-show="$root.status.installed" ng-controller="tcpdump_OptionsController">
    <div class="panel-heading pointer" data-toggle="collapse" data-target="#Options">
        <h4 class="panel-title">Options</h4>
    </div>
    <div id="Options" class="panel-collapse collapse">
	    <div class="panel-body">

          <div class="form-group">
              <div class="input-group">
                  <span class="input-group-addon input-sm">Command</span>
                  <input type="text" class="form-control input-sm" ng-model="command" placeholder="tcpdump command">
              </div>
          </div>

          <div class="form-group">
              <div class="input-group">
                  <span class="input-group-addon input-sm">Interface</span>
                  <select ng-change="update()" ng-model="selectedInterface" class="form-control input-sm">
                      <option>--</option>
                      <option ng-repeat="interface in interfaces">{{ interface }}</option>
                  </select>
              </div>
          </div>

          <div class="form-group">
              <div class="input-group">
                <span class="input-group-addon input-sm">Verbose</span>
                <select ng-change="update()" ng-model="verbose" class="form-control input-sm">
                  <option>--</option>
                  <option value="-v">Verbose</option>
                  <option value="-vv">Very verbose</option>
                  <option value="-vvv">Very very verbose</option>
                </select>
              </div>
          </div>

          <div class="form-group">
              <div class="input-group">
                <span class="input-group-addon input-sm">Resolve</span>
                <select ng-change="update()" ng-model="resolve" class="form-control input-sm">
                  <option>--</option>
                  <option value="-n">Don't resolve hostnames</option>
                  <option value="-nn">Don't resolve hostnames or port names</option>
                </select>
              </div>
          </div>

          <div class="form-group">
              <div class="input-group">
                <span class="input-group-addon input-sm">Timestamp</span>
                <select ng-change="update()" ng-model="timestamp" class="form-control input-sm">
                  <option>--</option>
                  <option value="-t">Don't print a timestamp on each dump line</option>
                  <option value="-tt">Print an unformatted timestamp on each dump line</option>
                  <option value="-ttt">Print a delta (micro-second resolution) between current and previous line on each dump line</option>
                  <option value="-tttt">Print a timestamp in default format proceeded by date on each dump line</option>
                  <option value="-ttttt">Print a delta (micro-second resolution) between current and first line on each dump line</option>
                </select>
              </div>
          </div>

          <div class="form-group">
              <div class="input-group">
                <div class="checkbox"><label><input type="checkbox" ng-change="update()" ng-model="dumpOptions.option1" ng-true-value="'-N'"> Don't print domain name qualification of host names</label></div>
                <div class="checkbox"><label><input type="checkbox" ng-change="update()" ng-model="dumpOptions.option2" ng-true-value="'-X'"> Show the packet's contents in both hex and ASCII</label></div>
                <div class="checkbox"><label><input type="checkbox" ng-change="update()" ng-model="dumpOptions.option3" ng-true-value="'-S'"> Print absolute sequence numbers</label></div>
                <div class="checkbox"><label><input type="checkbox" ng-change="update()" ng-model="dumpOptions.option4" ng-true-value="'-e'"> Get the ethernet header as well</label></div>
                <div class="checkbox"><label><input type="checkbox" ng-change="update()" ng-model="dumpOptions.option5" ng-true-value="'-q'"> Show less protocol information</label></div>
                <div class="checkbox"><label><input type="checkbox" ng-change="update()" ng-model="dumpOptions.option6" ng-true-value="'-I'"> Monitor mode</label></div>
              </div>
          </div>

          <div class="panel panel-default">
              <div class="panel-heading pointer" data-toggle="collapse" data-target="#Filter">Filter</div>
              <div id="Filter" class="panel-collapse collapse">
                <div class="panel-body">
                  <div class="form-group">
                      <div class="input-group">
                          <span class="input-group-addon input-sm">Filter</span>
                          <input ng-change="update()" type="text" class="form-control input-sm" ng-model="filter" placeholder="Filter">
                      </div>
                  </div>
                  <div class="form-group">
                    <div class="input-group">
                      <span class="input-group-addon input-sm">Type</span>
                      <div class="btn-group">
                      	<button class="btn btn-default btn-sm" ng-click="appendFilter('host')">host</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('net')">net</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('portrange')">portrange</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('port')">port</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('gateway')">gateway</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('mask')">mask</button>
          			      </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <div class="input-group">
                      <span class="input-group-addon input-sm">Dir</span>
                      <div class="btn-group">
                      	<button class="btn btn-default btn-sm" ng-click="appendFilter('src')">src</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('dst')">dst</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('src or dst')">src or dst</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('src and dst')">src and dst</button>
          			      </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <div class="input-group">
                      <span class="input-group-addon input-sm">Proto</span>
                      <div class="btn-group">
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('ip')">ip</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('proto')">proto</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('icmp')">icmp</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('tcp')">tcp</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('udp')">udp</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('arp')">arp</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('ether')">ether</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('http')">http</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('ftp')">ftp</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('smtp')">smtp</button>
                      </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <div class="input-group">
                      <span class="input-group-addon input-sm">Length</span>
                      <div class="btn-group">
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('less')">less</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('greater')">greater</button>
                      </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <div class="input-group">
                      <span class="input-group-addon input-sm">Kind</span>
                      <div class="btn-group">
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('broadcast')">broadcast</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('multicast')">multicast</button>
                      </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <div class="input-group">
                      <span class="input-group-addon input-sm">Operator</span>
                      <div class="btn-group">
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('not')">not</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('and')">and</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('or')">or</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('\(')">(</button>
                        <button class="btn btn-default btn-sm" ng-click="appendFilter('\)')">)</button>
                      </div>
                    </div>
                  </div>

                </div>
              </div>
          </div>

	    </div>
	</div>
</div>

<div class="panel panel-default" ng-show="$root.status.installed" ng-controller="tcpdump_OutputController">
	<div class="panel-heading">
        <h4 class="panel-title pull-left">Output</h4>
		<div class="pull-right">
			Auto-refresh <div class="btn-group">
			<button ng-click="toggleAutoRefresh()" class="btn btn-xs btn-{{refreshLabelON}}">ON</button>
			<button ng-click="toggleAutoRefresh()" class="btn btn-xs btn-{{refreshLabelOFF}}">OFF</button>
			</div>
		</div>
		<div class="clearfix"></div>
    </div>
    <div class="panel-body">
        <div class="btn-group pull-right">
          <button class="btn btn-primary btn-sm" ng-click="refreshOutput()">Refresh Log</button>
          <button class="btn btn-danger btn-sm" ng-click="clearOutput()">Clear Log</button>
        </div>
        <div class="clearfix"></div>
		<pre class="scrollable-pre log-pre">{{output}}</pre>
    </div>
</div>

<div class="panel panel-default" ng-show="$root.status.installed" ng-controller="tcpdump_HistoryController">
    <div class="panel-heading pointer" data-toggle="collapse" data-target="#History">
        <h4 class="panel-title">History <span class="badge">{{history.length}}</span></h4>
    </div>
    <div id="History" class="panel-collapse collapse">
        <div class="panel-body">
	        <button class="btn btn-primary btn-sm pull-right" ng-click="refreshHistory()">Refresh History</button><div class="clearfix"></div>
			<div class="table-responsive">
	            <table class="table table-striped table-bordered table-hover" ng-hide="(history.length == 0)">
	                <thead>
	                    <tr>
	                        <th>Date</th>
	                        <th>Action</th>
	                    </tr>
	                </thead>
	                <tbody>
	                    <tr ng-repeat="entry in history" ng-if="entry != ''">
	                        <td>{{entry[0]}}</td>
	                        <td>
								<div class="btn-group">
                  <button type="button" class="btn btn-fixed-length btn-sm btn-default" data-toggle="modal" data-target="#historyModal" ng-click="viewHistory(entry[1])">View</button>
                  <button type="button" class="btn btn-sm btn-default" ng-click="downloadHistory(entry[1])">Download</button>
									<button type="button" class="btn btn-fixed-length btn-sm btn-danger" ng-click="deleteHistory(entry[1])">Delete</button>
								</div>
							</td>
	                    </tr>
	                </tbody>
	            </table>
	        </div>
			<div class="well" ng-show="(history.length === 0)">No history...</div>
        </div>
    </div>

	<div class="modal fade" id="historyModal" tabindex="-1" role="dialog" aria-labelledby="historyModalLabel">
	  <div class="modal-dialog modal-lg" role="document">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="historyModalLabel">View History - {{historyDate}}</h4>
	      </div>
	      <div class="modal-body">
	      <pre class="scrollable-pre log-pre">{{historyOutput}}</pre>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
	      </div>
	    </div>
	  </div>
	</div>

</div>
